<?php
class Admin_AuthController extends Admin_Libraries_Controller_Action
{
	protected $_objAuth = null;
	
	public function init() {
		parent::init();
		$this->_objAuth = new Core_Auth('admin');	
		$this->_helper->layout()->setLayout('login');
	}
	
	public function loginAction() {		
		if ($this->_objAuth->isLogged()) {
			$this->_redirect('/admin');
		}			
		if ($this->getRequest()->isPost()) {
			$post = $this->getRequest()->getPost();			
			$username = $post['username'];
			$password = $post['passwd'];
			if ($this->_objAuth->login($username, $password)) {
				$redirectLink = base64_decode($post['return']);
				if (isset($redirectLink) && $redirectLink != '') {
					$this->_redirect($redirectLink);
				} else {
					$this->_redirect('/admin/auth/login');
				}
			}			
		}
		$this->view->return = $this->getRequest()->getParam('return', '');
	}
	
	public function logoutAction() {
		$this->_helper->viewRenderer->setNoRender(TRUE);	
		if ($this->_objAuth->isLogged()) $this->_objAuth->logout();
		$this->_redirect('/admin/auth/login');
	}
}